package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/personnelAll")
public class PersonnelLocationAllController {

    @GetMapping("/message")
    public void p(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject = new JSONObject();
        JSONObject json = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();
        JSONObject xinxi3 = new JSONObject();

        JSONArray Array = new JSONArray();
        jsonObject.put("instruction","updatepoi");
        json.put("updatetype","resetrenyuan");
        json.put("poigroup","renyuanAll");
        json.put("poitype","renyuanAll");

        xinxi.put("用户Id","192");
        xinxi.put("姓名","唐勇");
        xinxi.put("部门","安保部");
        xinxi.put("手机号","13333000000");
        xinxi.put("X","-8000");
        xinxi.put("Y","1500");

        xinxi1.put("用户Id","191");
        xinxi1.put("姓名","郑磊");
        xinxi1.put("部门","C班");
        xinxi1.put("手机号","13127559873");
        xinxi1.put("X","-7078");
        xinxi1.put("Y","1234");

        xinxi2.put("用户Id","193");
        xinxi2.put("姓名","杨小玲");
        xinxi2.put("部门","上海石洞口煤气制气有限公司");
        xinxi2.put("手机号","13917964158");
        xinxi2.put("X","-6778");
        xinxi2.put("Y","1634");

        xinxi3.put("用户Id","190");
        xinxi3.put("姓名","徐明珍");
        xinxi3.put("部门","C班");
        xinxi3.put("手机号","13816385005");
        xinxi3.put("X","-5789");
        xinxi3.put("Y","1334");

        Array.add(xinxi);
        Array.add(xinxi1);
        Array.add(xinxi2);
        Array.add(xinxi3);
        json.put("Array",Array);
        jsonObject.put("param",json);
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");

        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction","showpoi");
        json2.put("showtype","dygroup");
        json2.put("poigroup","renyuanAll");
        json2.put("poitype","renyuanAll");
        jsonObject2.put("param",json2);
//        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");

        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
            } else {
                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
            }
        }
    }
}
